﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Classes;
using ProgNetComponents.Interfaces;
using System.ComponentModel;
using System.Drawing.Design;
using ProgNetComponentsDx.Data.Design;
using ProgNetComponents.Controls;

namespace ProgNetComponentsDx.Data
{
    [TypeConverter(typeof(SelectDataTypeConverter))]
    public class SelectData : INamedObject
    {
        private string _Name;
        public SelectData() { }

        public SelectData(string name, RecordSelectStruct[] recordSelect)
        {
            Name = name;
            RecordSelect.AddRange(recordSelect);
        }

        private RecordSelectStructCollection _RecordSelect = new RecordSelectStructCollection();

        public string Name
        {
            get { return _Name; }
            set { _Name = ProgNetComponents.Tools.ConstHelper.GetFriendlyName(value); }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public RecordSelectStructCollection RecordSelect
        {
            get { return _RecordSelect; }
        }

        public override string ToString()
        {
            return Name;
        }
    }

    public class SelectDataCollection : ProgNetComponents.Collections.BaseNamedCollection<SelectData>
    {

    }

    public abstract class SelectDataNames
    {

    }

    [Designer(typeof(ProgNetComponents.Design.Designers.CollectionComponentDesigner))]
    public class SelectDataContainer : Component
    {
        private SelectDataGroupCollection _Items = new SelectDataGroupCollection();
        
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public SelectDataGroupCollection Items
        {
            get { return _Items; }
        }
    }


    [TypeConverter(typeof(SelectDataGroupTypeConverter))]
    public class SelectDataGroup : BaseNamedObject, INamedGroup
    {
        public SelectDataGroup()
        {

        }
        public SelectDataGroup(string name)
            : this(name, null, null)
        {

        }
        public SelectDataGroup(string name, SelectData[] browsers)
            : this(name, null, browsers)
        {
        }
        public SelectDataGroup(string name, SelectDataGroup[] groups)
            : this(name, groups, null)
        {
        }
        public SelectDataGroup(string name, SelectDataGroup[] groups, SelectData[] browsers)
        {
            Name = name;
            if (groups != null)
                Groups.AddRange(groups);
            if (browsers != null)
                Items.AddRange(browsers);
        }

        SelectDataCollection _Items = new SelectDataCollection();
        SelectDataGroupCollection _Groups = new SelectDataGroupCollection();

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public SelectDataCollection Items
        {
            get
            {
                return _Items;
            }
        }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public SelectDataGroupCollection Groups
        {
            get { return _Groups; }
        }

        #region INamedGroup Members

        System.Collections.IList INamedGroup.Groups
        {
            get { return _Groups; }
        }

        System.Collections.IList INamedGroup.Items
        {
            get { return _Items; }
        }

        bool INamedGroup.HasAnyItems()
        {
            if (_Items.Count > 0)
                return true;
            foreach (INamedGroup g in _Groups)
                if (g.HasAnyItems())
                    return true;
            return false;
        }

        #endregion

    }

    [Editor(typeof(SelectDataGroupCollectionEditor), typeof(System.Drawing.Design.UITypeEditor))]
    public class SelectDataGroupCollection : ProgNetComponents.Collections.BaseNamedCollection<SelectDataGroup>
    {

    }
}
